//
//  ViewController.m
//  LOL
//
//  Created by student on 16/3/3.
//  Copyright © 2016年 niit. All rights reserved.
//

#import "ViewController.h"
#import "lolModel.h"
@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (strong,nonatomic) NSArray *iconArr;
@property (strong,nonatomic) NSArray *introArr;
@property (strong,nonatomic) NSArray *nameArr;
@property (strong,nonatomic) NSArray *arr;
@end

@implementation ViewController

- (NSArray *)arr
{
    if (_arr == nil) {
        _arr = [lolModel lolModel];
    }
    return _arr;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    NSMutableArray *iconArr = [NSMutableArray array];
    NSMutableArray *introArr = [NSMutableArray array];
    NSMutableArray *nameArr = [NSMutableArray array];
    for (lolModel *lm in self.arr) {
        [iconArr addObject:lm.icon];
        [introArr addObject:lm.intro];
        [nameArr addObject:lm.name];
    }
    self.iconArr = iconArr;
    self.introArr = introArr;
    self.nameArr = nameArr;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.iconArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];// 查找已移除屏幕的单元格，进行复用
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
    }
    cell.textLabel.text = self.nameArr[indexPath.row];
    cell.imageView.image = [UIImage imageNamed:self.iconArr[indexPath.row]];
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"Intro" message:self.introArr[indexPath.row] delegate:self cancelButtonTitle:@"好的" otherButtonTitles:nil];
    [alertView show ];
}

@end
